﻿using TaoSH.AppCode;
using TaoSH.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace TaoSH.View
{
    public partial class SPGL : FormUControl
    {




        #region//添加页面asd


        public override void initALLForm(string strFormCode)
        {
            base.initALLForm(strFormCode);
            new BLLHelp.BindData().BindSPLB(conSPLB1, "0");
            new BLLHelp.BindData().BindSPBQ(donSPBQ);
            donSPBQ.Items.Insert(0, new ListItem("请选择", ""));


        }


        public override void initAddForm(string strFormCode)
        {
            conSPLB1.Items.Insert(0, new ListItem("请选择", ""));
        }




        /// <summary>
        /// 送审表单
        /// </summary>
        /// <param name="FormID">表单号</param>
        /// <param name="intProcessInstanceID">流程号</param>
        /// <returns></returns>
        public override bool SaveForm(int intFormID, string strActionType)
        {
            PT_Pro_Product MODEL = new PT_Pro_Product();
            MODEL = new PT_Pro_ProductB().GetEntity(d => d.ID == intFormID);
            MODEL.Category1 = int.Parse(conSPLB1.SelectedValue);
            MODEL.Category2 = int.Parse(conSPLB2.SelectedValue);

            MODEL.Title = conSPName.Value;

            MODEL.Price1 = decimal.Parse(conSCJ.Value);
            MODEL.Price2 = decimal.Parse(conXSJ.Value);
            MODEL.Price3 = decimal.Parse(conCBJ.Value);

            MODEL.ImgUrl = conSPTP.Value;
            MODEL.ImgUrl1 = conSPTP.Value.Split(',')[0].ToString();
            MODEL.Details = conSPXX.Text;
            MODEL.IsSelf = int.Parse(conSJ.SelectedValue);

            MODEL.Summary = conSummary.Value;
            MODEL.SpBQ = donSPBQ.SelectedValue;
            MODEL.SPSX1 = hidData.Value;
            if (strActionType == "ADD")
            {
                MODEL.Deleted = 0;

            }
            new PT_Pro_Product_SXB().Delete(d => d.SPID == intFormID);
            JArray ja = (JArray)JsonConvert.DeserializeObject(hidData.Value);
            foreach (JObject item in ja)
            {
                string strSXName = item["sxname"].ToString();
                string strSXValue = item["sxvalue"].ToString();

                foreach (string value in strSXValue.Split(','))
                {
                    new PT_Pro_Product_SXB().Insert(new PT_Pro_Product_SX() { SXName = strSXName, SPID = intFormID, SXValue = value, CreateTime = DateTime.Now, CreateUser = UserInfo.User.UserName });
                }

            }
            return new PT_Pro_ProductB().Update(MODEL);
        }
        #endregion

        #region//查看页面
        /// <summary>
        /// 初始化View页面
        /// </summary>
        /// <param name="intFormID">表单号</param>
        public override void initMangerForm(int intFormID)
        {

            PT_Pro_Product MODEL = new PT_Pro_Product();
            MODEL = new PT_Pro_ProductB().GetEntity(d => d.ID == intFormID);

            conSPLB1.SelectedValue = MODEL.Category1.ToString();
            new BLLHelp.BindData().BindSPLB(conSPLB2, conSPLB1.SelectedValue);
            conSPLB2.SelectedValue = MODEL.Category2.ToString();

            conSPName.Value = MODEL.Title;
            conSCJ.Value = MODEL.Price1.ToString();
            conXSJ.Value = MODEL.Price2.ToString();
            conCBJ.Value = MODEL.Price3.ToString();

            conSPTP.Value = MODEL.ImgUrl;
            conSPXX.Text = MODEL.Details;



            conSJ.SelectedValue = MODEL.IsSelf.ToString();
            donSPBQ.SelectedValue = MODEL.SpBQ;
            conSummary.Value = MODEL.Summary;
            hidData.Value = MODEL.SPSX1;

        }

        #endregion

        protected void conSPLB1_SelectedIndexChanged(object sender, EventArgs e)
        {
            new BLLHelp.BindData().BindSPLB(conSPLB2, conSPLB1.SelectedValue);

        }







    }
}